package com.bw.attendance

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.attendance.databinding.ActivityAttendanceBinding
import com.bw.common.base.BaseActivity
import com.bw.common.path.RouthPath
import dagger.hilt.android.AndroidEntryPoint

@Route(path = RouthPath.PATH_ATTENDANCE_PAGE)
@AndroidEntryPoint
class AttendanceActivity : BaseActivity<ActivityAttendanceBinding>() {
    @Autowired
    @JvmField
    var moduleType :String ="7"

    override fun initViews() {
        ARouter.getInstance().inject(this)
        initModuleFragment()
        //返回点击事件
        mDataBind.includePageTitle.ivBack.setOnClickListener {
            this.finish()
        }

    }

    override fun getLayoutId(): Int = R.layout.activity_attendance

    private fun initModuleFragment(){
        when(moduleType){
            "11" ->{
                mDataBind.includePageTitle.tvTitle.text = "签到"
                commitFragment(SignlnFragment.newInstance(),moduleType)
            }
            "12"->{
                mDataBind.includePageTitle.tvTitle.text = "考勤管理"
                commitFragment(AttendanceManagerFragment.newInstance(),moduleType)
            }

        }
    }

    /**
     * 提交fragment到当前的Activity
     */
    private fun commitFragment(moduleFragment: Fragment, fragmentTag:String){
        //1.获取FragmentManager对象
        var fm = supportFragmentManager
        //2.开启事务
        var fragmentTransaction = fm.beginTransaction()
        //3.提交事务
        fragmentTransaction.replace(R.id.fragment_container,moduleFragment,fragmentTag)
        fragmentTransaction.commit()
    }

}